layui.define([ 'form', 'laydate', 'table', ], function(exports) {
	var form = layui.form;
	var table = layui.table;
    var index = layui.index;
    
   var view = {
       init:function(){
       
        this.initSubmit();
        
        },
        initSubmit:function(){
        	
        	var i = 1;
        	
        	$(document).on('click','#addImg_up',function(){
        		if($(".addFeedbach_img").length == 6){       	   	 
        		layer.alert('亲，最多上传6张图片哦!', {icon: 2});
        		$("#addImg_up + div").remove();
           		 return false;
       		}       		
        	});   
        	
        	 	 
        		//上传图片
 	 		   $.files_up_oss({
 	 				id:"addImg_up",//按钮id
 	 		        url: "/oss/getSignatureNew",
 	 		        dir: "user/feedback/",
 	 		        file_type: "jpg,png,gif,psd,ai,cdr,eps,ppt,word,excel,pdf,tiff,rar,zip,7z,gif",
 	 		        size: "100mb",//mb
 	 		        view_url: "https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/"					
 	 			},function(index_number,json){										 
 	 				 if (json.Status == 'OK') {			 
 	 					 $(".upload_img").prepend('<div class="feed_img"><span><img class="addFeedbach_img" data-type="excel" data-item="'+ json.filename +'" src="https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/' + json.filename+'"><i class="del" id="addImg'+i+'"><font color="white">x</i></font></i></spqn></div>');	 				
 	 					 i++; 	
 	 					if($(".addFeedbach_img").length == 6){ 
 	 						$("#addImg_up").hide();
 	 					}
 	 					}
 	 		      });
     		
        		$(document).on("click",".del",function(){  			
        			var index = $(this).index();
        			$(".del").eq(index-1).parents(".feed_img").remove(); 	
        			if($(".addFeedbach_img").length < 6){ 
    					$("#addImg_up").show();
    				}
        		});

        	  //提交反馈
        	  $(document).on('click','.feedback_btn',function(){
        		  var imgSize = $(".addFeedbach_img").length;
        		  var fbPic="";
        		  for(var j=0;j<imgSize;j++){
        			  if(j == imgSize){
        				  fbPic += $(".addFeedbach_img").attr("data-item");
        			  }
        			      fbPic += $(".addFeedbach_img").attr("data-item")+",";  
        			  }
        		  
        		  var fbTitle = $(".category").val();
        		  if(fbTitle == "功能意见"){
        			  fbTitle = 1;
        		  }else if(fbTitle == "界面意见"){
        			  fbTitle = 2;
        		  }else if(fbTitle == "您的新需求"){
        			  fbTitle = 3;
        		  }else if(fbTitle == "操作意见"){
        			  fbTitle = 4;
        		  }else if(fbTitle == "其他"){
        			  fbTitle = 5;
        		  } 
        		  
        		  var fbContent = $(".feed_yj textarea").val();
        		  var fbPhone = $(".feed_lx input").val();
        		         		  
        		  if(fbTitle == "" || fbTitle == null){
                   	 layer.alert('请选择反馈意见类型', {icon: 2});
                   	 return false;
                    }
        		  if(fbContent == "" || fbContent == null){
                  	 layer.alert('请输入您的意见', {icon: 2});
                  	 return false;
                   }      		 
        		  if(!(/^1[34578]\d{9}$/.test(fbPhone))){
                  	 layer.alert('请输入11位有效的手机号', {icon: 2});
                  	 return false;
                   }
        		  
        		  var feedbackParam={
        				  "fbTitle":fbTitle,
        				  "fbContent":fbContent,
        				  "fbPic":fbPic,
        				  "fbPhone":fbPhone
        		  }
        		  
        		  $.post("/user/userFeedback/addFeedback.do",{"feedbackParam":JSON.stringify(feedbackParam)},fbback);
        		  
        		  function fbback(data){                  
                   	 if(data.code == '1'){
                   		window.location.href = "/user/userFeedback/feedbackSuccess.do"; 
                        }else{
                       	 layer.alert(data.msg, {icon: 2});
                        }
                   	 
                    }
        	  });
 		   
         
       	
       }
      
        
   }
     exports('index',view);
    });